﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

/*
 * Author:Conis
 * Date:
 * Description:对Web页面传值的扩展
 */
namespace Conis.Squirrel
{
    /// <summary>
    /// 对Web页面传值的扩展
    /// </summary>
    public class QueryHeler
    {
        #region 读取页面传来的参数
        /// <summary>
        /// 获取Post方式传送过来的参数
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetForm(string key)
        {
            return StringHelper.ObjectToString(HttpContext.Current.Request.Form[key]);
        }

        /// <summary>
        /// 获取Get方式传送过来的参数
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetQuery(string key)
        {
            return StringHelper.ObjectToString(HttpContext.Current.Request.QueryString[key]);
        }

        /// <summary>
        /// 获取Session
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetSession(string key)
        {
            return StringHelper.ObjectToString(HttpContext.Current.Session[key]);
        }

        /// <summary>
        /// 获取Cookies数据
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetCookies(string key)
        {
            return StringHelper.ObjectToString(HttpContext.Current.Request.Cookies[key].Value);
        }


        /// <summary>
        /// 设置cookies数据
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public static void SetCookies(string key, string value)
        {
            HttpContext.Current.Request.Cookies[key].Value = value;
        }

        /// <summary>
        /// 设置Session数据
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public static void SetSession(string key, string value)
        {
            HttpContext.Current.Session[key] = value;
        }

        /// <summary>
        /// 根据名称获取Cookies/Post/Get之任一的数据
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetParam(string key)
        {
            return StringHelper.ObjectToString(HttpContext.Current.Request.Params[key]);
        }
        #endregion
    }
}
